
#include "atomic_op_namespace.h"

#include <sys/atomic.h>

uint8_t atomic_and_8_nv(volatile uint8_t *addr, uint8_t val);

uint8_t
atomic_and_8_nv(volatile uint8_t *addr, uint8_t val)
{
	uint8_t old, new;

	do {
		old = *addr;
		new = old & val;
	} while (atomic_cas_8(addr, old, new) != old);

	return (new);
}

#undef atomic_and_8_nv
atomic_op_alias(atomic_and_8_nv,_atomic_and_8_nv)
crt_alias(__sync_and_and_fetch_1,_atomic_and_8_nv)
